package com.bxait.toymail.product.controller;

import java.util.Arrays;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import com.bxait.com.vo.product.SpuSaveVo;
import com.mysql.cj.log.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.product.entity.SpuInfoEntity;
import com.bxait.toymail.product.service.SpuInfoService;

import javax.annotation.Resource;


/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * spu信息
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:26:35
 */
@Slf4j
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {

    @Resource
    @Qualifier("spuInfoService")
    private SpuInfoService spuInfoService;
    

    /*
     * @param skuId
     * @==============History===============<br/>
     * @Description //   根据skuId获取spu信息
     * @Date 2023/5/13 2023/5/13 
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return com.bxait.com.utils.R
     */
    @GetMapping("/skuId/{id}")
    public R getSpuInfoBySkuId(@PathVariable("id") Long skuId){
        SpuInfoEntity entity = spuInfoService.getSpuInfoBySkuId(skuId);
        log.error("spuInfo{}",entity.toString());
        return R.ok().setData(entity);
    }

    /**
     * @param params
     * @==============History===============<br/>
     * @Description // TODO  获取商品的spu列表
     * @Date 2023/3/20 21:08 
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */ 
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);
        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * @param
     * @==============History===============<br/>
     * @Description // TODO  保存商品spu信息
     * @Date 2023/3/20 21:29
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return com.bxait.com.utils.R
     */ 
    @RequestMapping("/save")
    public R save(@RequestBody SpuSaveVo vo){
        spuInfoService.saveSpuInfo(vo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /*
     * @param spuId  商品的spuid
     * @==============History===============<br/>
     * @Description // 上架商品信息到es中
     * @Date 2023/4/13 22:17
     * @Author <a href="qq:2277411582@qq.com">chen</a>
     * @return
     */
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable("spuId") Long spuId){
        spuInfoService.up(spuId);
        return R.ok();
    }

}
